//                        ElgProg
//
//    A cheap DIY Arduino based Universal Programmer
//
//    Copyright (C) Elgen };-P aka Morten Overgaard 2015
//
//    This file is part of ElgProg.
//
//    ElgProg is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    ElgProg is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with ElgProg. If not, see <http://www.gnu.org/licenses/>.

#include <LiquidCrystal.h>
#include <EpromLib.h>

#define baudRate 115200
#define dataBufferSize (unsigned long)1024

int backLight   = 10;
int lightLevel  = 10;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
byte currentBuffer[dataBufferSize];
byte nextBuffer[dataBufferSize];
Eprom eprom(&lcd, dataBufferSize, currentBuffer, nextBuffer);

void setup()
{
  analogWrite(backLight, lightLevel);
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  
  Serial.begin(baudRate);
}

void loop()
{
  lcd.clear();
  lcd.print("Waiting for");
  lcd.setCursor(0, 1);
  lcd.print("command");
  while(Serial.available() == 0);
  String command = Serial.readStringUntil('\n');
  lcd.clear();
  lcd.print(command);
  if(command == "conf")
    eprom.readConfig();
  else if(command == "verify")
    eprom.verifyConf();
  else if(command == "read")
    eprom.readEprom();
  else if(command == "who")
    Serial.write("EPROM\n");
}

